# Contributor: Hygna <hygna@proton.me>
# Contributor: Fabricio Silva <hi@fabricio.dev>
# Maintainer: Fabricio Silva <hi@fabricio.dev>
pkgname=pnpm
pkgver=9.12.3
pkgrel=0
pkgdesc="Fast, disk space efficient package manager"
url="https://pnpm.io"
arch="noarch"
license="MIT"
depends="nodejs"
subpackages="
	$pkgname-doc
	$pkgname-bash-completion
	$pkgname-zsh-completion
	$pkgname-fish-completion
	"
source="https://registry.npmjs.org/pnpm/-/pnpm-$pkgver.tgz
	0001-no-check-for-updates.patch
	0002-no-self-update.patch
	"
builddir="$srcdir/package"

prepare() {
	default_prepare

	# remove node-gyp
	rm -rf dist/node-gyp-bin dist/node_modules/node-gyp
	# remove windows files
	rm -rf dist/vendor/*.exe

	# remove other unnecessary files
	find . -type f \( \
		-name '.*' -o \
		-name '*.cmd' -o \
		-name '*.bat' -o \
		-name '*.map' -o \
		-name '*.md' -o \
		-name '*.darwin*' -o \
		-name '*.win*' -o \
		-iname 'README*' \) -delete
}

check() {
	./bin/pnpm.cjs --help
}

package() {
	local destdir="$pkgdir"/usr/share/node_modules/$pkgname

	install -Dm644 LICENSE -t "$pkgdir"/usr/share/licenses/$pkgname

	install -Dm644 dist/templates/completion.bash \
		"$pkgdir"/usr/share/bash-completion/completions/$pkgname
	install -Dm644 dist/templates/completion.zsh \
		"$pkgdir"/usr/share/zsh/site-functions/_$pkgname
	install -Dm644 dist/templates/completion.fish \
		"$pkgdir"/usr/share/fish/vendor_completions.d/$pkgname.fish

	install -Dm644 package.json -t "$destdir"
	install -Dm755 bin/pnpm.cjs bin/pnpx.cjs -t "$destdir"/bin
	cp -r dist "$destdir"/dist

	mkdir -p "$pkgdir"/usr/bin
	ln -sf ../share/node_modules/pnpm/bin/pnpm.cjs "$pkgdir"/usr/bin/pnpm
	ln -sf ../share/node_modules/pnpm/bin/pnpx.cjs "$pkgdir"/usr/bin/pnpx
}

sha512sums="
cce0f9de9c5a7c95bef944169cc5dfe8741abfb145078c0d508b868056848a87c81e626246cb60967cbd7fd29a6c062ef73ff840d96b3c86c40ac92cf4a813ee  pnpm-9.12.3.tgz
f53903c506a676393dd8b31e1194b92612bfa877a8e17edc530e308921caf454248e181a3e620a17a941eba126349128963b2b0b1e48f8d927307c9cf335290e  0001-no-check-for-updates.patch
ac5e5abcf26f2d9aef00df5b67d48623ffa68c74f613bced7b95810b9a81e8d27c1b0530142e11adcb3ef04f7131887396b08303ad3540447468bda37d8b3854  0002-no-self-update.patch
"
